{template "header.html"}
<form class="form-horizontal login-form" action="" onsubmit="return dr_submit()" method="post" style="padding:50px 0">
    {$form}
    <div class="row myfbody">
        <div class="col-md-3"></div>
        <div class="col-md-6">
            <div class="portlet light bordered" style="margin-top: 40px">
                <div class="portlet-title">
                    <div class="caption">
                        <span class="caption-subject font-green"><b>{dr_lang('安全验证后台管理员账号')}</b></span>
                    </div>
                </div>
                <div class="portlet-body form">
                    <div class="form-body">
                        <div class="form-group" id="dr_row_username">
                            <label class="col-md-3 control-label ">{dr_lang('后台管理员账号')}</label>
                            <div class="col-md-7">
                                <input type="text" id="dr_username" class="form-control" name="data[username]">
                            </div>
                        </div>
                        <div class="form-group" id="dr_row_password">
                            <label class="col-md-3 control-label ">{dr_lang('后台管理员密码')}</label>
                            <div class="col-md-7">
                                <input type="password" id="dr_password" class="form-control" name="data[password]">
                            </div>
                        </div>
                        <div class="form-group dr_check " style="display: none">
                            <label class="col-md-3 control-label ">&nbsp;</label>
                            <div class="col-md-7 dr_check_phone">

                            </div>
                        </div>
                        <div class="form-group dr_check" style="display: none">
                            <input type="hidden" name="data[phone]" id="dr_check_phone">
                            <input type="hidden" name="is_check" id="is_check">
                            <label class="col-md-3 control-label ">&nbsp;</label>
                            <div class="col-md-7">
                            <div class="input-icon">
                                <div class="input-inline " style="margin-right: 0px;">
                                    <div class="input-group">
                                        <input type="text" name="data[sms]" placeholder="{dr_lang('手机验证码')}" id="dr_sms" class="form-control">
                                        <span class="input-group-btn">
                            <a class="btn default" onclick="dr_send_sms()">获取验证码</a>
                        </span>
                                    </div>
                                </div>
                            </div>
                            </div>
                        </div>

                        {if SYS_ADMIN_CODE}
                        <div class="form-group">
                            <label class="col-md-3 control-label ">{dr_lang('图片验证码')}</label>
                            <div class="col-md-7">
                                <div class="input-group login-code">
                                    <div class="input-icon">
                                        <input style="padding-left: 10px" class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="验证码" name="code">
                                    </div>
                                    <div class="input-group-btn fc-code">
                                        {dr_code(120, 35)}
                                    </div>
                                </div>
                            </div>
                        </div>
                        {/if}
                        <div class="form-group">
                            <label class="col-xs-3 control-label "></label>
                            <div class="col-xs-7">
                            <button type="button" onclick="dr_submit()" class="btn red " style="margin-right: 20px;"> {dr_lang('再次后台管理员账号')} </button>
                        </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
{if defined('SYS_ADMIN_LOGIN_AES') && SYS_ADMIN_LOGIN_AES}
<script src="{$THEME_PATH}assets/global/plugins/crypto-js.min.js?v={CMF_UPDATE_TIME}" type="text/javascript"></script>
{else}
<script src="{$THEME_PATH}assets/global/plugins/jquery.md5.js?v={CMF_UPDATE_TIME}" type="text/javascript"></script>
{/if}
<script type="text/javascript">
    var is_admin = 2;
    if (typeof parent.layer == 'function') {
        parent.layer.closeAll('loading');
    }

    function dr_send_sms() {
        $.ajax({type: "POST",dataType:"json", url: '{$sms_url}', data: $(".login-form").serialize(),
            success: function(json) {
                // token 更新
                if (json.token) {
                    var token = json.token;
                    $(".login-form input[name='"+token.name+"']").val(token.value);
                }
                if (json.code == 1) {
                    dr_tips(1, json.msg);
                } else {
                    $('.fc-code img').click();
                    dr_tips(0, json.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                $('.fc-code img').click();
                var msg = HttpRequest.responseText;
                if (!msg) {
                    dr_tips(0, "{dr_lang('系统错误')}");
                } else {
                    dr_tips(0, msg);
                }
            }
        });
    }
    function dr_submit() {
        // 这里进行md5加密存储
        var pwd = $('#dr_password').val();
        {if defined('SYS_ADMIN_LOGIN_AES') && SYS_ADMIN_LOGIN_AES}
        $('.login-form').append('<input type="hidden" name="is_aes" value="1">');
        var key = CryptoJS.enc.Utf8.parse('{$crypto_key}');
        var iv = CryptoJS.enc.Utf8.parse('{$crypto_iv}');
        var pw = pwd;
        pwd = CryptoJS.AES.encrypt(pwd, key, {
            mode: CryptoJS.mode.CBC,
            iv: iv,
            padding: CryptoJS.pad.Pkcs7
        });
        {if IS_DEV}
        pwd2 = CryptoJS.AES.decrypt(pwd, key, {
            mode: CryptoJS.mode.CBC,
            iv: iv,
            padding: CryptoJS.pad.Pkcs7
        });
        pwd2 = pwd2.toString(CryptoJS.enc.Utf8);
        if (pwd2 != pw) {
            alert("CryptoJS密码解析失败");
            return;
        }
        {/if}
        {else}
        pwd = $.md5(pwd); // 进行md5加密
        {/if}
        $('#dr_password').val(pwd);
        $.ajax({type: "POST",dataType:"json", url: '{$login_url}', data: $(".login-form").serialize(),
            success: function(json) {
                // token 更新
                if (json.token) {
                    var token = json.token;
                    $(".login-form input[name='"+token.name+"']").val(token.value);
                }
                if (json.code == 9) {
                    // 二次验证
                    $(".dr_row_username").hide();
                    $(".dr_row_password").hide();
                    $(".dr_check").show();
                    $(".dr_check_phone").html(json.msg);
                    $("#dr_check_phone").val(json.data);
                    $("#is_check").val("yes");
                    $('.fc-code img').click();
                } else if (json.code == 1) {
                    window.location.href = json.data.url;
                } else {
                    {if defined('SYS_ADMIN_LOGIN_AES') && SYS_ADMIN_LOGIN_AES}
                    $('#dr_password').val("");
                    {/if}
                    $('.fc-code img').click();
                    dr_tips(0, json.msg);
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                $('.fc-code img').click();
                dr_ajax_alert_error(HttpRequest, this, thrownError);
            }
        });
        return false;
    }
    jQuery(document).ready(function() {
        $('.login-form input').keypress(function (e) {
            if (e.which == 13) {
                dr_submit();
                return false;
            }
        });
    });
</script>
{template "footer.html"}